﻿@page
@model IceDog.EFCore.ContosoUniversity.Pages.Students.IndexModel

@{
    ViewData["Title"] = "Students";
}

<h2>Students</h2>

<p>
    <a asp-page="Create">Create New</a>
    <span> | </span>
    <a asp-page="CreateVM">Create New By ViewModel</a>
</p>
<form asp-page="./Index" method="get">
    <div class="form-actions no-color">
        <p>
            Find by name: <input type="text" name="SearchString" value="@Model.CurrentFilter" />
            <input type="submit" value="Search" class="btn btn-default" /> |
            <a asp-page="./Index">Back to full List</a>
            <div>
                <span>Try Search ? </span>
                <a asp-page="./Index" asp-route-searchString="a">a</a> |
                <a asp-page="./Index" asp-route-searchString="b">b</a> |
                <a asp-page="./Index" asp-route-searchString="c">c</a> |
            </div>
        </p>
    </div>
</form>
<table class="table table-bordered table-striped table-hover">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.Student[0].ID)
            </th>
            <th>
                <a asp-page="./Index" asp-route-sortOrder="@Model.NameSort"
                   asp-route-currentFilter="@Model.CurrentFilter">
                    @Html.DisplayNameFor(model => model.Student[0].LastName)
                </a>
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Student[0].FirstMidName)
            </th>
            <th>
                <a asp-page="./Index" asp-route-sortOrder="@Model.DateSort"
                   asp-route-currentFilter="@Model.CurrentFilter">
                    @Html.DisplayNameFor(model => model.Student[0].EnrollmentDate)
                </a>
            </th>
            <th>
                Operation
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.Student)
        {
            <tr>
                <td>
                    <a asp-page="./Details">@Html.DisplayFor(modelItem => item.ID)</a>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.LastName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.FirstMidName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.EnrollmentDate)
                </td>
                <td>
                    <a asp-page="./Edit" asp-route-id="@item.ID">Edit</a> |
                    <a asp-page="./EditVM" asp-route-id="@item.ID">EditVM</a> |
                    <a asp-page="./Details" asp-route-id="@item.ID">Details</a> |
                    <a asp-page="./Delete" asp-route-id="@item.ID">Delete</a>
                </td>
            </tr>
        }
    </tbody>
</table>
@{
    var prevDisabled = !Model.Student.HasPreviousPage ? "disabled" : "";
    var nextDisabled = !Model.Student.HasNextPage ? "disabled" : "";
}
<div>
    PageSize:
    <select id="page-size">
        <option value="3">3</option>
        <option value="5" selected="selected">5</option>
        <option value="10">10</option>
    </select>
    <script>
        var pageSize = document.querySelector("#page-size");
        pageSize.addEventListener("select", function (e) {
            debugger;
        });
    </script>
    <a asp-page="./Index"
       asp-route-sortOrder="@Model.CurrentSort"
       asp-route-pageIndex="@(Model.Student.PageIndex - 1)"
       asp-route-currentFilter="@Model.CurrentFilter"
       class="btn btn-default @prevDisabled">
        Previous
    </a>
    <a asp-page="./Index"
       asp-route-sortOrder="@Model.CurrentSort"
       asp-route-pageIndex="@(Model.Student.PageIndex + 1)"
       asp-route-currentFilter="@Model.CurrentFilter"
       class="btn btn-default @nextDisabled">
        Next
    </a>
    <span><span>@Model.Student.PageIndex</span> / <span>@Model.Student.TotalPages</span></span>
</div>